{% extends 'base.html.twig' %}
{% import 'Import/app_import.html.twig' as appImport %}

{% block head_title %}{{ 'indices'|trans }} - {{ index.name }} - {{ 'settings'|trans }}{% endblock %}

{% block heading_1 %}
    {{ appImport.heading({'level': 1, 'title': 'indices'|trans, 'link': {'url': path('indices')}}) }}
{% endblock %}

{% block heading_2 %}
    {{ appImport.heading({'level': 2, 'title': index.name, 'badge': {'title': index.health|trans, 'context': index.health}}) }}
{% endblock %}

{% block tabs %}
    {% include 'Modules/index/index_read_tabs.html.twig' with {'active': 'settings'} %}
{% endblock %}

{% block main_content %}
    {% embed 'Embed/block_embed.html.twig' %}
        {% import 'Import/app_import.html.twig' as appImport %}
        {% block content %}
            {{ appImport.heading({'level': 3, 'title': 'settings'|trans, 'badge': {'title': index.settings|length}}) }}

            {% if is_granted('INDEX_UPDATE', index) %}
                {% embed 'Embed/buttons_embed.html.twig' %}
                    {% block content %}
                        <a class="btn btn-primary btn-sm" href="{{ path('indices_setting_add', {'index': index.name}) }}">{{ 'add'|trans }}</a>
                    {% endblock %}
                {% endembed %}
            {% endif %}

            {% embed 'Embed/table_embed.html.twig' %}
                {% import 'Import/app_import.html.twig' as appImport %}

                {% block thead %}
                    <tr>
                        <th>{{ 'setting'|trans }}</th>
                        <th>{{ 'value'|trans }}</th>
                        {% if is_granted('INDEX_UPDATE', index) %}
                            <th>&nbsp;</th>
                        {% endif %}
                    </tr>
                {% endblock %}

                {% block tbody %}
                    {% for key, value in index.settings %}
                        <tr>
                            <td>{{ key }}</td>
                            <td>
                                {% if value is iterable %}
                                    {{ value|join(', ') }}{{ appImport.badge({'title': 'array'|trans, 'context': 'secondary'}) }}
                                {% else %}
                                    {{ value }}
                                {% endif %}
                            </td>

                            {% if is_granted('INDEX_UPDATE', index) %}
                                <td class="text-nowrap text-right">
                                    {% if value is not iterable and key not in exclude_settings %}
                                        {{ appImport.buttonModal({
                                            'id': 'SettingRemove' ~ loop.index,
                                            'title': 'remove'|trans,
                                            'body': key,
                                            'href': path('indices_setting_remove', {'index': index.name, 'setting': key}),
                                        }) }}

                                        <a class="btn btn-primary btn-sm" href="{{ path('indices_setting_update', {'index': index.name, 'setting': key}) }}">
                                            {{ ('update')|trans }}
                                        </a>
                                    {% endif %}
                                </td>
                            {% endif %}
                        </tr>
                    {% endfor %}
                {% endblock %}
            {% endembed %}
        {% endblock %}
    {% endembed %}
{% endblock %}
